package com.cmcc.aregister.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.cmcc.aregister.cs.model.MemberModel;

public class ChoiceQuickMemberAdapter extends BaseAdapter {
    private Context context = null;
    public List<MemberModel> list = null;

    public ChoiceQuickMemberAdapter(Context context, List<MemberModel> list) {
        this.context = context;
        this.list = list;
    }

    public int getCount() {
        return list.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.a_choice_member_dlg, null);
            holder.name = (TextView) convertView.findViewById(R.id.name);

            holder.relation = (TextView) convertView.findViewById(R.id.relation);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }
        MemberModel memberModel = list.get(position);
        holder.name.setText(memberModel.truename);
        holder.relation.setText(ConfigUtilHelper.getRelationText(context,memberModel.relation,memberModel.sex));

        return convertView;
    }

    static class ViewHolder {
        TextView name;
        TextView relation;
    }
}